import { Token } from '@/types/data'

// 封装存储localStorage的操作
const TOKEN_KEY = 'geek-h5-sh92-token'
export function setToken(token: Token): void {
  localStorage.setItem(TOKEN_KEY, JSON.stringify(token))
}

export function getToken(): Token {
  return JSON.parse(localStorage.getItem(TOKEN_KEY) || '{}')
}

export function removeToken(): void {
  localStorage.removeItem(TOKEN_KEY)
}

export function hasToken(): boolean {
  return !!getToken().token
}
